package cn.edu.scau.cmi.liguanwu.consistentcomposite;

import java.util.HashSet;
import java.util.Set;

public class ConsistentTeam extends ConsistentOrangization{
	private ConsistentOrangization Parent;
	private String name;
	private Set<ConsistentOrangization> children=new HashSet<ConsistentOrangization>();
	@Override
	public void doSomething() {
			System.out.println("This is Team "+name+".");
			if(Parent!=null) {
				System.out.println("	We blong to "+((ConsistentTeam)Parent).getName());
			}
			if(children.size()>0)
				for (ConsistentOrangization item : children) {
	                 if(item.getClass()==ConsistentTeam.class) {
	                	 System.out.println("	Team "+item.getName()+" do good jobs.");
	                 }
	                 else if(item.getClass()==ConsistentPerson.class) {
	                	 System.out.println("	Person "+item.getName()+" do good jobs.");
	                 }
			    }
	}
	public void setParent(ConsistentOrangization Parent) {
	    this.Parent=Parent;
	}
	@Override
	public ConsistentOrangization getParent() {
		return this.Parent;
	}
	public ConsistentOrangization getperson(String nam) {
		ConsistentOrangization tmp=null;
		if(children.size()>0)
			for (ConsistentOrangization item : children) {
				if(item.getClass()==ConsistentPerson.class&&nam.equals(item.getName())) {
					tmp=item;
				}
			}
		return tmp;
	}
	public ConsistentOrangization addChild(ConsistentOrangization child){
		children.add(child);
		return this;
	}
	public ConsistentOrangization removeChild(ConsistentOrangization child){
		children.remove(child);
		return this;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
